package com.sumer.psychology.photo.infrastructure.persistence.mongo;

import com.mongodb.DBObject;
import com.sumer.psychology.common.persistence.mongodb.AbstractSimpleMongoRepository;

/**
 * User: zhenguang.zhu
 * Date: 2014/10/29
 * Time: 15:39
 */
public class MongoPhotoRepository extends AbstractSimpleMongoRepository {
    private static final String DB_NAME = "sumer_photo";
    private static final String PHOTO_KEY = "photoId.identity";

    @Override
    public void add(String data) {
        DBObject photo = initializeCreateData(data, key());
        String albumId = nestedValue(photo, "albumId.identity");
        photo.put("albumId", albumId);
        photo.put("views", 0);
        photo.put("replies", 0);

        db().getCollection(dbName()).insert(photo);
    }

    @Override
    protected String key() {
        return PHOTO_KEY;
    }

    @Override
    protected String dbName() {
        return DB_NAME;
    }
}
